const webpack = require('webpack')
var path = require('path')
    //项目根目录
var rootPath = path.resolve(__dirname, "..")

//plugins
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var baseConfig = {
    entry: {
        app: path.join(rootPath, "/src/app.js")
    },
    resolve: {
        extensions: ['', '.js', '.json'],
        alias: {
            'js': path.resolve(rootPath, 'src/js'),
            'assets': path.resolve(rootPath, 'src/assets'),
            'css': path.resolve(rootPath, 'src/css')
        },
        modulesDirectories: ["web_modules", "node_modules", "bower_components"],
        fallback: [path.join(__dirname, '../node_modules')]

    },

    module: {
        loaders: [{
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'react', 'stage-0']
                }
            }, {
                test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf|otf)(\?.*)?$/,
                loader: 'url?limit=8192&context=client&name=assets/imgs/[path][name].[hash:7].[ext]'
            },
            {
                test: /\.(mp3|wma)$/i,
                loader: 'file-loader?name=assets/sound/[name].[hash:7].[ext]'
            },

            {
                test: /\.css$/,
                loader: ExtractTextPlugin.extract("style", "css")
            },

            {
                test: /\.scss$/,
                loader: 'style!css!autoprefixer!sass'

            }
        ]

    },
    plugins: [
        //create html 
        new HtmlWebpackPlugin({
            filename: "index.html",
            template: "src/index.html",
            inject: 'head'
        }),
        //extract css
        new ExtractTextPlugin("css/[name].css"),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery"
        })
    ]

};



module.exports = baseConfig;